USE [master]
GO
/****** Object:  Database [RD4_DWCRWork]    Script Date: 5/30/13 10:27:52 AM ******/
IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = N'RD4_DWCRWork')
BEGIN
CREATE DATABASE [RD4_DWCRWork] ON  PRIMARY 
( NAME = N'RD4_DWCRWork', FILENAME = N'D:\Database File\RD4_DWCRWork.mdf' , SIZE = 10947264KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%)
 LOG ON 
( NAME = N'RD_DWCRWork_log', FILENAME = N'I:\Database Logs\RD_DWCRWork_log.ldf' , SIZE = 629888KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
END

GO
ALTER DATABASE [RD4_DWCRWork] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [RD4_DWCRWork].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO
ALTER DATABASE [RD4_DWCRWork] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET ARITHABORT OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [RD4_DWCRWork] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [RD4_DWCRWork] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [RD4_DWCRWork] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET  ENABLE_BROKER 
GO
ALTER DATABASE [RD4_DWCRWork] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [RD4_DWCRWork] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [RD4_DWCRWork] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [RD4_DWCRWork] SET  MULTI_USER 
GO
ALTER DATABASE [RD4_DWCRWork] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [RD4_DWCRWork] SET DB_CHAINING OFF 
GO
EXEC sys.sp_db_vardecimal_storage_format N'RD4_DWCRWork', N'ON'
GO

/****** Object:  StoredProcedure [dbo].[UE_JDEGSUDC_ainsupddel]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UE_JDEGSUDC_ainsupddel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE	PROCEDURE [dbo].[UE_JDEGSUDC_ainsupddel] 
-------------------------------------------------------------------------------
--Procedure Name:		UE_JDEGSUDC_ainsupddel   		
--Author:			Andrews Consulting Group        
--Date Created:			04/24/03						
--Date Modified/By: 03/39/2005 ACG to include SourceID for better performance
--Date Modified/By: 07/26/2005 ACG to dynamically assign UE table per environment
-------------------------------------------------------------------------------
-- This procedure executes as a user exit after update, insert, or delete and 
-- maintains the value_trans table in the DM MetaData database.					
-------------------------------------------------------------------------------
@Entry int, 
@SuccessInd int OUTPUT,
@RtnMessage char(50) OUTPUT,
@SelectInd int OUTPUT
AS
	SELECT @SuccessInd = 1
	SELECT @RtnMessage = ''Nothing''
---------------------------------------
--BEGIN:  DECLARATION SECTION
---------------------------------------
DECLARE @SourceID		AS Int
DECLARE @AffectsValueTrans	AS CHAR(3)
DECLARE @InstallSystemCode	AS CHAR(4)
DECLARE @UserDefinedCode	AS CHAR(2)
DECLARE @Description		AS CHAR(30)
DECLARE	@UserDefinedCodesValues 	AS CHAR(10)
DECLARE @SQLString		AS NVARCHAR(4000)	
DECLARE @UETable 		AS VARCHAR(50)
DECLARE @ParmDefinition 	AS NVARCHAR(500)
DECLARE @Quote			AS CHAR(1)
---------------------------------------
--END:  DECLARATION SECTION
---------------------------------------
SET ANSI_PADDING ON
SET @Quote = ''''''''
/*
--BEGIN:  Reference purposes @Entry points
BEFORE_CLEAR    ( 1)
AFTER_CLEAR     ( 2)
BEFORE_INSERT   ( 3)
AFTER_INSERT    ( 4)
BEFORE_UPDATE   ( 5)
AFTER_UPDATE    ( 6)
BEFORE_DELETE   ( 7)
AFTER_DELETE    ( 8)
BEFORE_REFRESH  ( 9)
AFTER_REFRESH   (10)
BEFORE_STARTUP  (11)
AFTER_STARTUP   (12)
--END:  Reference purposes @Entry points
*/
		
---------------------------------------
--BEGIN:  IDENTIFY WHAT UE TABLE TO USE			
---------------------------------------			
DECLARE @HOSTNAME AS VARCHAR(255)
SELECT DISTINCT @HOSTNAME = HOST_NAME() 
SELECT @UETable = UETableName
FROM RD_DWCR.dbo.ValueTransHostSource  
WHERE  HostName = @HOSTNAME
---------------------------------------
--END:  IDENTIFY WHAT UE TABLE TO USE
---------------------------------------
-- UPDATE / INSERT PROCESSING

IF @Entry = 8	
-- DELETE, BASED ON BEFORE IMAGE
BEGIN
	SET @SQLString	= N''SELECT	
							@InstallSystemCodeOUT 	= DRSY, 
							@UserDefinedCodeOUT 	= DRRT,
							@UserDefinedCodesValuesOUT = DRKY
						FROM RD_DWCR_UE.dbo.''+@UETable+''_bef''

	SET @ParmDefinition = N''@InstallSystemCodeOUT char(4) OUTPUT,
							@UserDefinedCodeOUT char(2) OUTPUT,
							@UserDefinedCodesValuesOUT char(10) OUTPUT''
				
	EXEC sp_executesql 
			@SQLString,
			@ParmDefinition,
			@InstallSystemCodeOUT	= @InstallSystemCode OUTPUT,
			@UserDefinedCodeOUT	= @UserDefinedCode OUTPUT,
			@UserDefinedCodesValuesOUT 	= @UserDefinedCodesValues OUTPUT

END
ELSE
-- WHEN NO DELETE, BASED ON UPDATE IMAGE
BEGIN
	SET @SQLString = N''SELECT 	@SourceIDOUT			= SourceID,
							@InstallSystemCodeOUT 		= InstallSystemCode, 
							@UserDefinedCodeOUT 		= UserDefinedCode,
							@UserDefinedCodesValuesOUT 	= UserDefinedCodesValues
			    		FROM RD_DWCR_UE.dbo.''+@UETable +''_upd''
	SET @ParmDefinition = N''@SourceIDOUT Int OUTPUT,
        	                @InstallSystemCodeOUT char(4) OUTPUT,
							@UserDefinedCodeOUT char(2) OUTPUT,
							@UserDefinedCodesValuesOUT char(10) OUTPUT'' 

	EXEC sp_executesql 
			@SQLString,
			@ParmDefinition,
			@SourceIDOUT 			= @SourceID OUTPUT,
			@InstallSystemCodeOUT 		= @InstallSystemCode OUTPUT,
			@UserDefinedCodeOUT 		= @UserDefinedCode OUTPUT,
			@UserDefinedCodesValuesOUT 	= @UserDefinedCodesValues OUTPUT

END 

-- DOES CHANGE AFFECT VAL TRANS?
SELECT   @AffectsValueTrans = 
				CASE
					WHEN EXISTS(
						SELECT InstallSystemCode
						FROM RD_DWCR.dbo.ValueTransFieldReferences
						WHERE 	InstallSystemCode	= @InstallSystemCode	AND
						 	UserDefinedCode		= @UserDefinedCode)
					THEN ''Yes''
					ELSE ''No''
					END
/*****************************************************************************************/
/**********                	Before Clear 					**********/
/*****************************************************************************************/
--if (@Entry = 1)
--begin	
--	exec master.dbo.xp_logevent 65000,''UE Ran Entry 1'',Informational
--end
/*****************************************************************************************/
/**********                	After Clear 					**********/
/*****************************************************************************************/
--if (@Entry = 2)
--begin	
--	exec master.dbo.xp_logevent 65000,''UE Ran Entry 2'',Informational
--end
/*****************************************************************************************/
/**********                	Before Insert 					**********/
/*****************************************************************************************/
--if (@Entry = 3)
--begin		
--	exec master.dbo.xp_logevent 65000,''UE Ran Entry 3'',Informational
--end
/*****************************************************************************************/
/**********                	After Insert 					**********/
/*****************************************************************************************/

If    @Entry = 4
BEGIN
IF @AffectsValueTrans = ''Yes''
BEGIN
SET @SQLSTRING = (''	INSERT INTO TransformationServer52.dbo.DTST_VALUE_TRANS
			SELECT	srcsysid	= VTFR.srcsysid,
				srcfilnme	= VTFR.srcfilnme,
				srcfillib	= VTFR.srcfillib,
				tgtentnme	= VTFR.tgtentnme,
				tgtschema	= VTFR.tgtschema,
				atrnme		= VTFR.atrnme,
				atroldval	= RIGHT(UPD.UserDefinedCodesValues,UDT.CodeLength),
				atrnewval	= ISNULL(LEFT(UPD.Description01,26),space(25) + ''''.''''),
				tgtdb		= VTFR.tgtdb
			FROM	RD_DWCR.dbo.ValueTransFieldReferences   VTFR
			INNER JOIN RD_DWCR_UE.dbo.''+@UETable+''_upd UPD 	
			ON	VTFR.InstallSystemCode	= UPD.InstallSystemCode AND
				VTFR.UserDefinedCode	= UPD.UserDefinedCode 	AND
				VTFR.SourceID		= UPD.SourceID
			INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodeTypes UDT 
			ON	UPD.InstallSystemCode	= UDT.InstallSystemCode AND
			 	UPD.UserDefinedCode	= UDT.UserDefinedCode 	AND
			 	UPD.SourceID		= UDT.SourceID
			WHERE NOT EXISTS (	SELECT *
						FROM TransformationServer52.dbo.DTST_VALUE_TRANS dts2
						WHERE	dts2.srcfilnme 	= VTFR.srcfilnme		AND
							dts2.tgtentnme	= VTFR.tgtentnme		AND
							dts2.atrnme		= VTFR.atrnme		AND
							dts2.atroldval	= UPD.UserDefinedCodesValues 	AND
							dts2.srcsysid 	= VTFR.srcsysid	)'')
	
EXEC (@SQLString)	
	-- mark tables that use the affected system/userdefined code as requiring nightly update.
		Update 
			RD_DWCR.dbo.ValueTransFieldReferences
		Set
			UpdateNightlyStatus	= ''Yes''
		Where
			InstallSystemCode	= @InstallSystemCode	and
		 	UserDefinedCode		= @UserDefinedCode
END 
 
 END
/*****************************************************************************************/
/**********                	Before UPDATE 					**********/
/*****************************************************************************************/
--IF (@Entry = 5)
--BEGIN	
--	exec master.dbo.xp_logevent 65000,''UE Ran Entry 5'',Informational
--END
/*****************************************************************************************/
/**********                	After UPDATE 					**********/
/*****************************************************************************************/
IF @Entry = 6
BEGIN	
IF @AffectsValueTrans = ''Yes''
	BEGIN
	-- update code description in value trans table, column atrnewval
	SET @SQLString = (''	UPDATE TransformationServer52.dbo.DTST_VALUE_TRANS
				SET	atrnewval = ISNULL(LEFT(UPD.Description01,26),space(25) + ''''.'''')
				FROM TransformationServer52.dbo.DTST_VALUE_TRANS VT
				INNER JOIN RD_DWCR_UE.dbo.''+@UETable+''_upd UPD 	
				ON	UPD.InstallSystemCode	=  @spInstallSystemCode AND
				 	UPD.UserDefinedCode	=  @spUserDefinedCode
				INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodeTypes	UDT 
				ON 	UPD.InstallSystemCode	= UDT.InstallSystemCode AND
				 	UPD.UserDefinedCode	= UDT.UserDefinedCode AND
				 	UPD.SourceID	= UDT.SourceID 
		 		INNER JOIN RD_DWCR.dbo.ValueTransFieldReferences   VTFR 
			 	ON	VTFR.tgtentnme	= VT.tgtentnme AND
				 	VTFR.atrnme	= VT.atrnme AND
				 	VTFR.InstallSystemCode	=  @spInstallSystemCode AND
				 	VTFR.UserDefinedCode	=  @spUserDefinedCode AND
					VTFR.srcsysid	= VT.srcsysid AND
					VTFR.SourceID	= UPD.SourceID AND
					RIGHT(UPD.UserDefinedCodesValues,UDT.CodeLength) 	= LEFT(VT.atroldval , UDT.CodeLength)'')
	
	
	SET @ParmDefinition = N''@spSourceID Int ,
		        	                @spInstallSystemCode Char (4),
									@spUserDefinedCode char(2),
									@spUserDefinedCodesValues char(10)'' 


	EXEC sp_executesql 
		@SQLString,
		@ParmDefinition,
		@spSourceID				= @SourceID ,
		@spInstallSystemCode	= @InstallSystemCode,
		@spUserDefinedCode		= @UserDefinedCode,
		@spUserDefinedCodesValues 	= @UserDefinedCodesValues

-----------------------------------------------------------------------------------
-- MARK TABLE THAT USE THE AFFECTED SYSTEM/USER DEFINED CODE AS REQUIRING UPDATE.
-----------------------------------------------------------------------------------
-- Tables DESIGNATED FOR NIGHTLY UPDATE
	IF (	SELECT COUNT(*) 
		FROM RD_DWCR.dbo.ValueTransFieldReferences
		WHERE	InstallSystemCode	= @InstallSystemCode	AND
		 	UserDefinedCode		= @UserDefinedCode	AND
			UpdateOnline		= ''No'') > 0
	BEGIN
			UPDATE RD_DWCR.dbo.ValueTransFieldReferences
			SET	UpdateNightlyStatus	= ''Yes''
			WHERE	InstallSystemCode	= @InstallSystemCode	AND
				UserDefinedCode		= @UserDefinedCode	AND
				UpdateOnline		= ''No''
	END

-- RECORDS EXIST FOR online UPDATE
-- TABLES DESIGNATED FOR ONLINE UPDATE
	IF (	SELECT COUNT(*) 
		FROM RD_DWCR.dbo.ValueTransFieldReferences
		WHERE	InstallSystemCode	= @InstallSystemCode	AND
		 	UserDefinedCode		= @UserDefinedCode	AND
			UpdateOnline		= ''Yes'') > 0
	BEGIN
		-- CALL Update program to update tables based on pararmeters
		EXEC USP_Apply_UDC_Changes @SourceID,@UserDefinedCodesValues,@InstallSystemCode, @UserDefinedCode		
	
	END	-- RECORDS EXIST FOR ONLINE UPDATES

END -- END @AffectsValueTrans = ''Yes''

END
/*****************************************************************************************/
/**********                	Before Delete 					**********/
/*****************************************************************************************/
--if (@Entry = 7)
--begin	
--	exec master.dbo.xp_logevent 65000,''UE Ran Entry 7'',Informational
--end
/*****************************************************************************************/
/**********                	After Delete 					**********/
/*****************************************************************************************/

IF (@Entry = 8)
BEGIN
	
	IF @AffectsValueTrans = ''Yes''
	BEGIN
	SET @SQLString = ''''
	SET @SQLString = (''DELETE TransformationServer52.dbo.DTST_VALUE_TRANS
				FROM TransformationServer52.dbo.DTST_VALUE_TRANS VT
				INNER JOIN RD_DWCR_UE.dbo.''+@UETable+''_bef  BEF
				ON	BEF.DRSY	= @spInstallSystemCode AND
					BEF.DRRT	= @spUserDefinedCode
				INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodeTypes UDT
				ON	BEF.DRSY	= UDT.InstallSystemCode	and
				 	BEF.DRRT	= UDT.UserDefinedCode
				INNER JOIN RD_DWCR.dbo.ValueTransFieldReferences  VTFR 
				ON	VTFR.tgtentnme	= VT.tgtentnme AND
					VTFR.atrnme		= VT.atrnme AND
					VTFR.InstallSystemCode	= @spInstallSystemCode AND
					VTFR.UserDefinedCode	= @spUserDefinedCode AND
					VTFR.srcsysid	= VT.srcsysid AND
					RIGHT(@spUserDefinedCodesValues,UDT.CodeLength) = LEFT(VT.atroldval , UDT.CodeLength)'')
	
		SET @ParmDefinition = N''@spSourceID Int ,
	        	                @spInstallSystemCode Char (4),
								@spUserDefinedCode char(2),
								@spUserDefinedCodesValues char(10)'' 
	
		EXEC sp_executesql 
			@SQLString,
			@ParmDefinition,
			@spSourceID				= @SourceID ,
			@spInstallSystemCode	= @InstallSystemCode,
			@spUserDefinedCode		= @UserDefinedCode,
			@spUserDefinedCodesValues 	= @UserDefinedCodesValues

	END 

END
/*****************************************************************************************/
/**********                	Before Refresh 					**********/
/*****************************************************************************************/
--if (@Entry = 9)
--begin	
--	exec master.dbo.xp_logevent 65000,''UE Ran Entry 9'',Informational
--end
/*****************************************************************************************/
/**********                	After Refresh 					**********/
/*****************************************************************************************/
--if (@Entry = 10)
--begin	
--	exec master.dbo.xp_logevent 65000,''UE Ran Entry 10'',Informational
--end
/*****************************************************************************************/
/**********                	Before Startup 					**********/
/*****************************************************************************************/
--if (@Entry = 11)
--begin	 --	exec master.dbo.xp_logevent 65000,''UE Ran Entry 11'',Informational --end
/*****************************************************************************************/
/**********                	After Startup 					**********/
/*****************************************************************************************/
--if (@Entry = 12)
--begin	
--	exec master.dbo.xp_logevent 65000,''UE Ran Entry 12'',Informational
--end
/* end of stored procedure */
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[UE_JDEGSUDC_ainsupddel] TO  SCHEMA OWNER 
GO
/****** Object:  StoredProcedure [dbo].[UEDI_JDEGSUDC_Updates]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UEDI_JDEGSUDC_Updates]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE	PROCEDURE [dbo].[UEDI_JDEGSUDC_Updates] 
-------------------------------------------------------------------------------
--Procedure Name:		UE_JDEGSUDC_ainsupddel   		
--Author:			Andrews Consulting Group        
--Date Created:			04/24/03						
--Date Modified/By: 03/39/2005 ACG to include SourceID for better performance
--Date Modified/By: 07/26/2005 ACG to dynamically assign UE table per environment
-------------------------------------------------------------------------------
-- This procedure executes as a user exit after update, insert, or delete and 
-- maintains the value_trans table in the DM MetaData database.					
-------------------------------------------------------------------------------

AS

---------------------------------------
--BEGIN:  DECLARATION SECTION
---------------------------------------
DECLARE @SourceID		AS Int
DECLARE @InstallSystemCode	AS CHAR(4)
DECLARE @UserDefinedCode	AS CHAR(2)
DECLARE @Description01		AS CHAR(30)
DECLARE	@UserDefinedCodesValues 	AS CHAR(10)


-- Create Cursor to read through Work File 

DECLARE UDC_Change_Cursor CURSOR FOR
SELECT
		RTrim(SourceID),
		RTrim(InstallSystemCode),
		RTrim(UserDefinedCode),
		RTrim(UserDefinedCodesValues),
		RTrim(Description01)
FROM
		RD4_DWCRWork.dbo.JDEGSUDCUpdate w1
WHERE
		InsertTimeStamp = (select max(InsertTimestamp) 
					from RD4_DWCRWork.dbo.JDEGSUDCUpdate w2
					WHERE	w1.InstallSystemCode = w2.InstallSystemCode
						and	w1.UserDefinedCode = w2.UserDefinedCode
						and w1.UserDefinedCodesValues = w2.UserDefinedCodesValues
						and w1.SourceID = w2.SourceID)


OPEN UDC_Change_Cursor

-- Main Loop
FETCH NEXT FROM UDC_Change_Cursor
INTO 	@SourceID,
		@InstallSystemCode,
		@UserDefinedCode,
		@UserDefinedCodesValues,
		@Description01

WHILE @@FETCH_STATUS = 0
BEGIN

-- CALL Update program to update tables based on pararmeters
EXEC USPDI_Apply_UDC_Updates @SourceID,@UserDefinedCodesValues,@InstallSystemCode, @UserDefinedCode, @Description01


FETCH NEXT FROM UDC_Change_Cursor
INTO 	@SourceID,
		@InstallSystemCode,
		@UserDefinedCode,
		@UserDefinedCodesValues,
		@Description01

END 

CLOSE UDC_Change_Cursor
DEALLOCATE UDC_Change_Cursor

Truncate Table RD4_DWCRWork.dbo.JDEGSUDCUpdate

/* end of stored procedure */
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[UEDI_JDEGSUDC_Updates] TO  SCHEMA OWNER 
GO
/****** Object:  StoredProcedure [dbo].[USP_Apply_UDC_Changes]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_Apply_UDC_Changes]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE     PROCEDURE [dbo].[USP_Apply_UDC_Changes]
-------------------------------------------------------------------------------
--Procedure Name:	USP_Apply_UDC_Changes                                                                     
--Author:		c Copyright 2004 Andrews Consulting Group                                                                        
--Date Created:     04/25/2003                                                                                      
--Date Modified/By:                                                                                                  
-------------------------------------------------------------------------------
--This procedure is responsible for updating all tables affected by changes
--made to included codes in the UDC Table.
-------------------------------------------------------------------------------
	
@SourceID	as int,
@UserDefinedCodesValues as CHAR(10),
@InstallSystemCode	as char(4) ,
@UserDefinedCode	as char(2)	


AS

SET ANSI_PADDING ON

--exec master.dbo.xp_logevent 65000,''USP_Apply_UDC_Changes'',Informational

DECLARE
 	@srcfilnme			as varchar(128),
 	@tgtcodefield		as varchar(128),
	@tgtentnme			as varchar(128),
	@atrnme				as varchar(128),
	@UpdateStatus		as char(3),
	@ParmDefinition 	AS Nvarchar(500),
	@SQLCmd				as Nvarchar(4000)

DECLARE Change_Cursor CURSOR FOR
SELECT
		RTrim(srcfilnme),
		RTrim(tgtcodefield),
		RTrim(tgtentnme),
		RTrim(atrnme)
FROM
		RD_DWCR.dbo.ValueTransFieldReferences
WHERE
		InstallSystemCode =  @InstallSystemCode AND
		UserDefinedCode = @UserDefinedCode AND
		UpdateOnLine = ''Yes'' AND
		SourceID = @SourceID

OPEN Change_Cursor
-- Main Loop
FETCH NEXT FROM Change_Cursor
INTO 	@srcfilnme,
		@tgtcodefield,
		@tgtentnme,
		@atrnme

WHILE @@FETCH_STATUS = 0
BEGIN


	SET @SQLCmd = 	
			''UPDATE RD_DWCR.dbo.'' + @tgtentnme  + ''
			SET  '' + @atrnme + '' = UDC.[Description01]
			FROM RD_DWCR.dbo.'' + @tgtentnme  + '' as TGT 
			INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodeTypes AS UDT ON  
			UDT.InstallSystemCode = @spInstallSystemCode AND  
			UDT.UserDefinedCode	= @spUserDefinedCode AND
			UDT.SourceID =   @spSourceID 
			INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodes AS UDC ON  
			UDC.InstallSystemCode = @spInstallSystemCode AND  
			UDC.UserDefinedCode	=  @spUserDefinedCode AND 
			UDC.UserDefinedCodesValues =   @spUserDefinedCodesValues   AND
			UDC.SourceID =  @spSourceID 
			WHERE TGT.'' + @atrnme + '' <> UDC.Description01 AND
			LEFT('' +  @tgtcodefield  + '' , UDT.CodeLength) = RIGHT( @spUserDefinedCodesValues , UDT.CodeLength) AND 
			TGT.SourceID = @spSourceID ''
	
	SET @ParmDefinition = N''@spSourceID Int,
        	                @spInstallSystemCode char(4),
							@spUserDefinedCode char(2) ,
							@spUserDefinedCodesValues char(10)'' 


	PRINT @sqlcmd

	EXEC sp_executesql 
	@SQLCmd,
	@ParmDefinition,
	@spSourceID				= @SourceID ,
	@spInstallSystemCode	= @InstallSystemCode,
	@spUserDefinedCode		= @UserDefinedCode,
	@spUserDefinedCodesValues 	= @UserDefinedCodesValues

	/**
		BEGIN TRANSACTION
			EXEC (@SQLCmd)
		COMMIT
	**/

	-- Reset UpdateStatus in ColumnField Table
	BEGIN TRANSACTION
	Update 
		RD_DWCR.dbo.ValueTransFieldReferences
	Set 
		UpdateStatus = ''No''
	Where 
		tgtentnme 	= @tgtentnme AND
		atrnme		= @atrnme
	COMMIT

FETCH NEXT FROM Change_Cursor
INTO 	@srcfilnme,
		@tgtcodefield,
		@tgtentnme,
		@atrnme

END

CLOSE Change_Cursor
DEALLOCATE Change_Cursor
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[USP_Apply_UDC_Changes] TO  SCHEMA OWNER 
GO
/****** Object:  StoredProcedure [dbo].[USP_Apply_UDC_Changes_F0101]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_Apply_UDC_Changes_F0101]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE   PROCEDURE [dbo].[USP_Apply_UDC_Changes_F0101]
-------------------------------------------------------------------------------
--Procedure Name:	USP_Apply_UDC_Changes                                                                     
--Author:		c Copyright 2004 Andrews Consulting Group                                                                        
--Date Created:     04/25/2003                                                                                      
--Date Modified/By:                                                                                                  
-------------------------------------------------------------------------------
--This procedure is responsible for updating all tables affected by changes
--made to included codes in the UDC Table.
-------------------------------------------------------------------------------


AS

SET ANSI_PADDING ON


DECLARE

	@SourceID 			as int ,
	@tgtentnme			as varchar(128),
 	@tgtcodefield		as varchar(128),
	@atrnme				as varchar(128),
	@InstallSystemCode	as char(4),
	@UserDefinedCode	as char(2),
	@UpdateStatus		as char(3),
	@ParmDefinition 	AS Nvarchar(500),
	@SQLCmd				as Nvarchar(4000)


DECLARE Change_Cursor CURSOR FOR
SELECT	RTrim(tgtcodefield),
		SourceID ,
		RTrim(tgtentnme),
		RTrim(atrnme),
		InstallSystemCode,
		UserDefinedCode 
FROM
		RD_DWCR.dbo.ValueTransFieldReferences
WHERE
		srcfilnme = ''F0101''

OPEN Change_Cursor
-- Main Loop
FETCH NEXT FROM Change_Cursor
INTO 	@tgtcodefield,
		@SourceID,
		@tgtentnme,
		@atrnme,
		@InstallSystemCode,
		@UserDefinedCode 

WHILE @@FETCH_STATUS = 0
BEGIN

BEGIN TRAN
	SET @SQLCmd = 	
			''UPDATE RD_DWCR.dbo.'' + @tgtentnme  + ''
			SET  '' + @atrnme + '' = UDC.[Description01]
			FROM RD_DWCR.dbo.'' + @tgtentnme  + '' as TGT 
			INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodeTypes AS UDT ON  
			UDT.InstallSystemCode = @spInstallSystemCode  AND  
			UDT.UserDefinedCode	=  @spUserDefinedCode AND
			UDT.SourceID =  @spSourceID
			INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodes AS UDC ON  
			UDC.InstallSystemCode =  @spInstallSystemCode  AND  
			UDC.UserDefinedCode	=  @spUserDefinedCode AND 
			RIGHT(UDC.UserDefinedCodesValues, UDT.CodeLength) = LEFT('' +  @tgtcodefield  + '',UDT.CodeLength)  AND
			UDT.SourceID =  @spSourceID   ''
	--		WHERE TGT.'' + @atrnme + '' <> UDC.Description01 ''

	SET @ParmDefinition = N''@spSourceID Int,
        	                @spInstallSystemCode char(4),
							@spUserDefinedCode char(2)''

	EXEC sp_executesql 
		@SQLCmd,
		@ParmDefinition,
		@spSourceID				= @SourceID,
		@spInstallSystemCode	= @InstallSystemCode,
		@spUserDefinedCode		= @UserDefinedCode

COMMIT 

--print  cast (@SourceID as char(3)) + '' '' + @InstallSystemCode + '' '' + @UserDefinedCode

begin tran
	-- Reset UpdateStatus in ColumnField Table
	Update 
		RD_DWCR.dbo.ValueTransFieldReferences
	Set 
		UpdateNightlyStatus = ''No''
	Where 
		tgtentnme 	= @tgtentnme AND
		atrnme		= @atrnme
commit

	FETCH NEXT FROM Change_Cursor
	INTO	@tgtcodefield,
			@SourceID,
			@tgtentnme,
			@atrnme,
			@InstallSystemCode,
			@UserDefinedCode 
END

CLOSE Change_Cursor
DEALLOCATE Change_Cursor
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[USP_Apply_UDC_Changes_F0101] TO  SCHEMA OWNER 
GO
/****** Object:  StoredProcedure [dbo].[USP_Apply_UDC_Changes_Nightly]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_Apply_UDC_Changes_Nightly]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE   PROCEDURE [dbo].[USP_Apply_UDC_Changes_Nightly]
-------------------------------------------------------------------------------
--Procedure Name:	USP_Apply_UDC_Changes                                                                     
--Author:		c Copyright 2004 Andrews Consulting Group                                                                        
--Date Created:     04/25/2003                                                                                      
--Date Modified/By:                                                                                                  
-------------------------------------------------------------------------------
--This procedure is responsible for updating all tables affected by changes
--made to included codes in the UDC Table.
-------------------------------------------------------------------------------


AS

SET ANSI_PADDING ON


DECLARE

	@SourceID 			as int ,
	@tgtentnme			as varchar(128),
 	@tgtcodefield		as varchar(128),
	@atrnme				as varchar(128),
	@InstallSystemCode	as char(4),
	@UserDefinedCode	as char(2),
	@UpdateStatus		as char(3),
	@ParmDefinition 	AS Nvarchar(500),
	@SQLCmd				as Nvarchar(4000)


DECLARE Change_Cursor CURSOR FOR
SELECT	RTrim(tgtcodefield),
		SourceID ,
		RTrim(tgtentnme),
		RTrim(atrnme),
		InstallSystemCode,
		UserDefinedCode 
FROM
		RD_DWCR.dbo.ValueTransFieldReferences
WHERE
		UpdateNightlyStatus = ''Yes''

OPEN Change_Cursor
-- Main Loop
FETCH NEXT FROM Change_Cursor
INTO 	@tgtcodefield,
		@SourceID,
		@tgtentnme,
		@atrnme,
		@InstallSystemCode,
		@UserDefinedCode 

WHILE @@FETCH_STATUS = 0
BEGIN

BEGIN TRAN
	SET @SQLCmd = 	
			''UPDATE RD_DWCR.dbo.'' + @tgtentnme  + ''
			SET  '' + @atrnme + '' = UDC.[Description01]
			FROM RD_DWCR.dbo.'' + @tgtentnme  + '' as TGT 
			INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodeTypes AS UDT ON  
			UDT.InstallSystemCode = @spInstallSystemCode  AND  
			UDT.UserDefinedCode	=  @spUserDefinedCode AND
			UDT.SourceID =  @spSourceID
			INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodes AS UDC ON  
			UDC.InstallSystemCode =  @spInstallSystemCode  AND  
			UDC.UserDefinedCode	=  @spUserDefinedCode AND 
			RIGHT(UDC.UserDefinedCodesValues, UDT.CodeLength) = LEFT('' +  @tgtcodefield  + '',UDT.CodeLength)  AND
			UDT.SourceID =  @spSourceID   ''
	--		WHERE TGT.'' + @atrnme + '' <> UDC.Description01 ''

	SET @ParmDefinition = N''@spSourceID Int,
        	                @spInstallSystemCode char(4),
							@spUserDefinedCode char(2)''

	EXEC sp_executesql 
		@SQLCmd,
		@ParmDefinition,
		@spSourceID				= @SourceID,
		@spInstallSystemCode	= @InstallSystemCode,
		@spUserDefinedCode		= @UserDefinedCode

COMMIT 

--print  cast (@SourceID as char(3)) + '' '' + @InstallSystemCode + '' '' + @UserDefinedCode

begin tran
	-- Reset UpdateStatus in ColumnField Table
	Update 
		RD_DWCR.dbo.ValueTransFieldReferences
	Set 
		UpdateNightlyStatus = ''No''
	Where 
		tgtentnme 	= @tgtentnme AND
		atrnme		= @atrnme
commit

	FETCH NEXT FROM Change_Cursor
	INTO	@tgtcodefield,
			@SourceID,
			@tgtentnme,
			@atrnme,
			@InstallSystemCode,
			@UserDefinedCode 
END

CLOSE Change_Cursor
DEALLOCATE Change_Cursor
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[USP_Apply_UDC_Changes_Nightly] TO  SCHEMA OWNER 
GO
/****** Object:  StoredProcedure [dbo].[USPDI_Apply_UDC_Updates]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USPDI_Apply_UDC_Updates]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE    PROCEDURE [dbo].[USPDI_Apply_UDC_Updates]
-------------------------------------------------------------------------------
--Procedure Name:	USP_Apply_UDC_Changes                                                                     
--Author:		c Copyright 2004 Andrews Consulting Group                                                                        
--Date Created:     04/25/2003                                                                                      
--Date Modified/By:                                                                                                  
-------------------------------------------------------------------------------
--This procedure is responsible for updating all tables affected by changes
--made to included codes in the UDC Table.
-------------------------------------------------------------------------------
	
@SourceID	as int,
@UserDefinedCodesValues as CHAR(10),
@InstallSystemCode	as char(4) ,
@UserDefinedCode	as char(2),
@Description01 char(30)

AS

SET ANSI_PADDING ON

--exec master.dbo.xp_logevent 65000,''USP_Apply_UDC_Changes'',Informational

DECLARE
 	@srcfilnme			as varchar(128),
 	@tgtcodefield		as varchar(128),
	@tgtentnme			as varchar(128),
	@atrnme				as varchar(128),
	@UpdateStatus		as char(3),
	@ParmDefinition		as nvarchar(500),
	@SQLCmd				as nvarchar(4000)

DECLARE Change_Cursor CURSOR FOR
SELECT
		RTrim(srcfilnme),
		RTrim(tgtcodefield),
		RTrim(tgtentnme),
		RTrim(atrnme)
FROM
		RD_DWCR.dbo.ValueTransFieldReferences
WHERE
		InstallSystemCode =  @InstallSystemCode AND
		UserDefinedCode = @UserDefinedCode AND
		SourceID = @SourceID

OPEN Change_Cursor
-- Main Loop
FETCH NEXT FROM Change_Cursor
INTO 	@srcfilnme,
		@tgtcodefield,
		@tgtentnme,
		@atrnme

WHILE @@FETCH_STATUS = 0
BEGIN


	SET @SQLCmd = 	
			''UPDATE RD_DWCR.dbo.'' + @tgtentnme  + ''
			SET  '' + @atrnme + '' = @spDescription01  
			FROM RD_DWCR.dbo.'' + @tgtentnme  + '' as TGT 
			INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodeTypes AS UDT ON  
			UDT.InstallSystemCode = @spInstallSystemCode AND  
			UDT.UserDefinedCode	= @spUserDefinedCode AND
			UDT.SourceID =   @spSourceID 
			INNER JOIN RD_DWCR.dbo.JDEGSUserDefinedCodes AS UDC ON  
			UDC.InstallSystemCode = @spInstallSystemCode AND  
			UDC.UserDefinedCode	=  @spUserDefinedCode AND 
			UDC.UserDefinedCodesValues =   @spUserDefinedCodesValues   AND
			UDC.SourceID =  @spSourceID 
			WHERE TGT.'' + @atrnme + '' <> UDC.Description01 AND
			LEFT('' +  @tgtcodefield  + '' , UDT.CodeLength) = RIGHT( @spUserDefinedCodesValues , UDT.CodeLength) AND 
			TGT.SourceID = @spSourceID ''
	
	SET @ParmDefinition = N''@spSourceID Int,
        	                @spInstallSystemCode char(4),
							@spUserDefinedCode char(2) ,
							@spUserDefinedCodesValues char(10),
							@spDescription01 char(30)'' 


	--PRINT @sqlcmd

	EXEC sp_executesql 
	@SQLCmd,
	@ParmDefinition,
	@spSourceID				= @SourceID ,
	@spInstallSystemCode	= @InstallSystemCode,
	@spUserDefinedCode		= @UserDefinedCode,
	@spUserDefinedCodesValues 	= @UserDefinedCodesValues,
	@spDescription01		= @Description01



FETCH NEXT FROM Change_Cursor
INTO 	@srcfilnme,
		@tgtcodefield,
		@tgtentnme,
		@atrnme

END

CLOSE Change_Cursor
DEALLOCATE Change_Cursor
' 
END
GO
ALTER AUTHORIZATION ON [dbo].[USPDI_Apply_UDC_Updates] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[F9210]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[F9210]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[F9210](
	[FRDTAI] [nchar](10) NOT NULL,
	[FRCLAS] [nchar](10) NULL,
	[FRDTAT] [nchar](1) NULL,
	[FRDTAS] [numeric](5, 0) NULL,
	[FRDTAD] [numeric](2, 0) NULL,
	[FRPDTA] [nchar](10) NULL,
	[FRARRN] [numeric](3, 0) NULL,
	[FRDVAL] [nchar](40) NULL,
	[FRLR] [nchar](1) NULL,
	[FRCDEC] [nchar](1) NULL,
	[FRDRUL] [nchar](6) NULL,
	[FRDRO1] [nchar](40) NULL,
	[FRERUL] [nchar](6) NULL,
	[FRERO1] [nchar](40) NULL,
	[FRERO2] [nchar](40) NULL,
	[FRHLP1] [nchar](10) NULL,
	[FRHLP2] [nchar](10) NULL,
	[FRNNIX] [numeric](2, 0) NULL,
	[FRNSY] [nchar](4) NULL,
	[FRRLS] [nchar](10) NULL,
	[FRUSER] [nchar](10) NULL,
	[FRUPMJ] [numeric](6, 0) NULL,
	[FRPID] [nchar](10) NULL,
	[FRJOBN] [nchar](10) NULL,
	[FRUPMT] [numeric](6, 0) NULL,
	[FROWDI] [nchar](40) NULL,
	[FROWTP] [nchar](2) NULL,
	[FRCNTT] [nchar](1) NULL,
	[FRSCFG] [nchar](1) NULL,
	[FRUPER] [nchar](1) NULL,
	[FRALBK] [nchar](1) NULL,
	[FROWER] [nchar](6) NULL,
	[FROER1] [nchar](40) NULL,
	[FROER2] [nchar](40) NULL,
	[FROWDR] [nchar](6) NULL,
	[FRODR1] [nchar](40) NULL,
	[FRDBID] [decimal](31, 0) NULL,
	[FRBFDN] [nchar](32) NULL,
	[FREBID] [decimal](31, 0) NULL,
	[FRBFEN] [nchar](32) NULL,
	[FRSFID] [decimal](31, 0) NULL,
	[FRSFMN] [nchar](10) NULL,
	[FRBVID] [decimal](31, 0) NULL,
	[FRBVNM] [nchar](10) NULL,
	[FRPLFG] [nchar](1) NULL,
	[FRDDID] [decimal](31, 0) NULL,
	[FRAUIN] [nchar](1) NULL,
PRIMARY KEY CLUSTERED 
(
	[FRDTAI] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
ALTER AUTHORIZATION ON [dbo].[F9210] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[FBMobileUserFilterFields]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FBMobileUserFilterFields]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[FBMobileUserFilterFields](
	[UserID] [nchar](10) NOT NULL,
	[RouteCode] [nchar](3) NOT NULL,
	[CostCenter] [nchar](12) NOT NULL,
	[CostCenterHome] [nchar](12) NOT NULL,
	[BusinessUnitValue] [nchar](12) NOT NULL,
	[AddressNumber] [numeric](8, 0) NOT NULL,
	[AddressNumberParent] [numeric](8, 0) NOT NULL,
	[StopCode] [nchar](3) NOT NULL,
	[ZoneNumber] [nchar](3) NOT NULL,
	[Location] [nchar](20) NOT NULL,
	[LocationFrom] [nchar](20) NOT NULL,
	[EverestEventPoint01] [nchar](1) NOT NULL,
	[EverestEventPoint02] [nchar](1) NOT NULL,
	[EverestEventPoint03] [nchar](1) NOT NULL,
	[MathNumeric01] [decimal](15, 0) NULL,
	[MathNumeric02] [decimal](15, 0) NOT NULL,
	[MathNumeric03] [decimal](15, 0) NOT NULL,
	[DateExpirJulian] [numeric](6, 0) NOT NULL,
	[ClearedDateID] [numeric](6, 0) NOT NULL,
	[DateID] [numeric](6, 0) NOT NULL,
	[UpdatedByUser] [nchar](10) NOT NULL,
	[ProgramId] [nchar](10) NOT NULL,
	[WorkStationId] [nchar](10) NOT NULL,
	[DateUpdated] [numeric](6, 0) NOT NULL,
	[TimeLastUpdated] [numeric](6, 0) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[UserID] ASC,
	[RouteCode] ASC,
	[CostCenter] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
ALTER AUTHORIZATION ON [dbo].[FBMobileUserFilterFields] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[FBSalesOrganizationStructure]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FBSalesOrganizationStructure]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[FBSalesOrganizationStructure](
	[AddressNumber] [int] NOT NULL,
	[OperationLevel01] [int] NOT NULL,
	[OperationLevelDesc01] [char](40) NOT NULL,
	[OperationLevel02] [int] NOT NULL,
	[OperationLevelDesc02] [char](40) NOT NULL,
	[OperationLevel03] [int] NOT NULL,
	[OperationLevelDesc03] [char](40) NOT NULL,
	[OperationLevel04] [int] NOT NULL,
	[OperationLevelDesc04] [char](40) NOT NULL,
	[OperationLevel05] [int] NOT NULL,
	[OperationLevelDesc05] [char](40) NOT NULL,
	[OperationLevel06] [int] NOT NULL,
	[OperationLevelDesc06] [char](40) NOT NULL,
	[OperationLevel07] [int] NOT NULL,
	[OperationLevelDesc07] [char](40) NOT NULL,
	[OperationLevel08] [int] NOT NULL,
	[OperationLevelDesc08] [char](40) NOT NULL,
	[OperationLevel09] [int] NOT NULL,
	[OperationLevelDesc09] [char](40) NOT NULL,
	[OperationLevel10] [int] NOT NULL,
	[OperationLevelDesc10] [char](40) NOT NULL,
	[SalesLevel01] [int] NOT NULL,
	[SalesLevelDesc01] [char](40) NOT NULL,
	[SalesLevel02] [int] NOT NULL,
	[SalesLevelDesc02] [char](40) NOT NULL,
	[SalesLevel03] [int] NOT NULL,
	[SalesLevelDesc03] [char](40) NOT NULL,
	[SalesLevel04] [int] NOT NULL,
	[SalesLevelDesc04] [char](40) NOT NULL,
	[SalesLevel05] [int] NOT NULL,
	[SalesLevelDesc05] [char](40) NOT NULL,
	[SalesLevel06] [int] NOT NULL,
	[SalesLevelDesc06] [char](40) NOT NULL,
	[SalesLevel07] [int] NOT NULL,
	[SalesLevelDesc07] [char](40) NOT NULL,
	[SalesLevel08] [int] NOT NULL,
	[SalesLevelDesc08] [char](40) NOT NULL,
	[SalesLevel09] [int] NOT NULL,
	[SalesLevelDesc09] [char](40) NOT NULL,
	[SalesLevel10] [int] NOT NULL,
	[SalesLevelDesc10] [char](40) NOT NULL,
	[NAM01] [int] NOT NULL,
	[NAMDesc01] [char](40) NOT NULL,
	[NAM02] [int] NOT NULL,
	[NAMDesc02] [char](40) NOT NULL,
	[NAM03] [int] NOT NULL,
	[NAMDesc03] [char](40) NOT NULL,
	[NAM04] [int] NOT NULL,
	[NAMDesc04] [char](40) NOT NULL,
	[NAM05] [int] NOT NULL,
	[NAMDesc05] [char](40) NOT NULL,
	[NAM06] [int] NOT NULL,
	[NAMDesc06] [char](40) NOT NULL,
	[NAM07] [int] NOT NULL,
	[NAMDesc07] [char](40) NOT NULL,
	[NAM08] [int] NOT NULL,
	[NAMDesc08] [char](40) NOT NULL,
	[NAM09] [int] NOT NULL,
	[NAMDesc09] [char](40) NOT NULL,
	[NAM10] [int] NOT NULL,
	[NAMDesc10] [char](40) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[DateUpdated] [int] NOT NULL,
	[TimeofDay] [decimal](6, 0) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[AddressNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
ALTER AUTHORIZATION ON [dbo].[FBSalesOrganizationStructure] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[ItemBranchinDEV]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemBranchinDEV]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ItemBranchinDEV](
	[IBITM] [numeric](8, 0) NOT NULL,
	[IBLITM] [nchar](25) NULL,
	[IBAITM] [nchar](25) NULL,
	[IBMCU] [nchar](12) NOT NULL,
	[IBSRP1] [nchar](3) NULL,
	[IBSRP2] [nchar](3) NULL,
	[IBSRP3] [nchar](3) NULL,
	[IBSRP4] [nchar](3) NULL,
	[IBSRP5] [nchar](3) NULL,
	[IBSRP6] [nchar](6) NULL,
	[IBSRP7] [nchar](6) NULL,
	[IBSRP8] [nchar](6) NULL,
	[IBSRP9] [nchar](6) NULL,
	[IBSRP0] [nchar](6) NULL,
	[IBPRP1] [nchar](3) NULL,
	[IBPRP2] [nchar](3) NULL,
	[IBPRP3] [nchar](3) NULL,
	[IBPRP4] [nchar](3) NULL,
	[IBPRP5] [nchar](3) NULL,
	[IBPRP6] [nchar](6) NULL,
	[IBPRP7] [nchar](6) NULL,
	[IBPRP8] [nchar](6) NULL,
	[IBPRP9] [nchar](6) NULL,
	[IBPRP0] [nchar](6) NULL,
	[IBCDCD] [nchar](15) NULL,
	[IBPDGR] [nchar](3) NULL,
	[IBDSGP] [nchar](3) NULL,
	[IBVEND] [numeric](8, 0) NULL,
	[IBANPL] [numeric](8, 0) NULL,
	[IBBUYR] [numeric](8, 0) NULL,
	[IBGLPT] [nchar](4) NULL,
	[IBORIG] [nchar](3) NULL,
	[IBROPI] [decimal](15, 0) NULL,
	[IBROQI] [decimal](15, 0) NULL,
	[IBRQMX] [decimal](15, 0) NULL,
	[IBRQMN] [decimal](15, 0) NULL,
	[IBWOMO] [decimal](7, 0) NULL,
	[IBSERV] [decimal](7, 3) NULL,
	[IBSAFE] [decimal](15, 0) NULL,
	[IBSLD] [decimal](6, 0) NULL,
	[IBCKAV] [nchar](1) NULL,
	[IBSRCE] [nchar](1) NULL,
	[IBLOTS] [nchar](1) NULL,
	[IBOT1Y] [nchar](1) NULL,
	[IBOT2Y] [nchar](1) NULL,
	[IBSTDP] [decimal](7, 0) NULL,
	[IBFRMP] [decimal](7, 0) NULL,
	[IBTHRP] [decimal](7, 0) NULL,
	[IBSTDG] [nchar](3) NULL,
	[IBFRGD] [nchar](3) NULL,
	[IBTHGD] [nchar](3) NULL,
	[IBCOTY] [nchar](1) NULL,
	[IBMMPC] [decimal](7, 0) NULL,
	[IBPRGR] [nchar](8) NULL,
	[IBRPRC] [nchar](8) NULL,
	[IBORPR] [nchar](8) NULL,
	[IBBACK] [nchar](1) NULL,
	[IBIFLA] [nchar](2) NULL,
	[IBABCS] [nchar](1) NULL,
	[IBABCM] [nchar](1) NULL,
	[IBABCI] [nchar](1) NULL,
	[IBOVR] [nchar](1) NULL,
	[IBSHCM] [nchar](3) NULL,
	[IBCARS] [numeric](8, 0) NULL,
	[IBCARP] [numeric](8, 0) NULL,
	[IBSHCN] [nchar](3) NULL,
	[IBSTKT] [nchar](1) NULL,
	[IBLNTY] [nchar](2) NULL,
	[IBFIFO] [nchar](1) NULL,
	[IBCYCL] [nchar](3) NULL,
	[IBINMG] [nchar](10) NULL,
	[IBWARR] [nchar](8) NULL,
	[IBSRNR] [nchar](1) NULL,
	[IBPCTM] [decimal](7, 0) NULL,
	[IBCMCG] [nchar](8) NULL,
	[IBFUF1] [nchar](1) NULL,
	[IBTX] [nchar](1) NULL,
	[IBTAX1] [nchar](1) NULL,
	[IBMPST] [nchar](1) NULL,
	[IBMRPD] [nchar](1) NULL,
	[IBMRPC] [nchar](1) NULL,
	[IBUPC] [decimal](15, 0) NULL,
	[IBSNS] [nchar](1) NULL,
	[IBMERL] [nchar](3) NULL,
	[IBLTLV] [numeric](5, 0) NULL,
	[IBLTMF] [numeric](5, 0) NULL,
	[IBLTCM] [numeric](5, 0) NULL,
	[IBOPC] [nchar](1) NULL,
	[IBOPV] [decimal](15, 0) NULL,
	[IBACQ] [decimal](15, 0) NULL,
	[IBMLQ] [decimal](15, 0) NULL,
	[IBLTPU] [numeric](5, 0) NULL,
	[IBMPSP] [nchar](1) NULL,
	[IBMRPP] [nchar](1) NULL,
	[IBITC] [nchar](1) NULL,
	[IBECO] [nchar](12) NULL,
	[IBECTY] [nchar](2) NULL,
	[IBECOD] [numeric](6, 0) NULL,
	[IBMTF1] [decimal](5, 0) NULL,
	[IBMTF2] [decimal](5, 0) NULL,
	[IBMTF3] [decimal](5, 0) NULL,
	[IBMTF4] [decimal](5, 0) NULL,
	[IBMTF5] [decimal](5, 0) NULL,
	[IBMOVD] [numeric](5, 0) NULL,
	[IBQUED] [numeric](5, 0) NULL,
	[IBSETL] [decimal](15, 0) NULL,
	[IBSRNK] [decimal](15, 0) NULL,
	[IBSRKF] [nchar](1) NULL,
	[IBTIMB] [nchar](1) NULL,
	[IBBQTY] [decimal](15, 0) NULL,
	[IBORDW] [nchar](1) NULL,
	[IBEXPD] [numeric](5, 0) NULL,
	[IBDEFD] [numeric](5, 0) NULL,
	[IBMULT] [decimal](15, 0) NULL,
	[IBSFLT] [numeric](5, 0) NULL,
	[IBMAKE] [nchar](1) NULL,
	[IBLFDJ] [numeric](6, 0) NULL,
	[IBLLX] [decimal](3, 0) NULL,
	[IBCMGL] [nchar](1) NULL,
	[IBURCD] [nchar](2) NULL,
	[IBURDT] [numeric](6, 0) NULL,
	[IBURAT] [decimal](15, 0) NULL,
	[IBURAB] [numeric](8, 0) NULL,
	[IBURRF] [nchar](15) NULL,
	[IBUSER] [nchar](10) NULL,
	[IBPID] [nchar](10) NULL,
	[IBJOBN] [nchar](10) NULL,
	[IBUPMJ] [numeric](6, 0) NULL,
	[IBTDAY] [decimal](6, 0) NULL,
	[IBTFLA] [nchar](2) NULL,
	[IBCOMH] [decimal](3, 0) NULL,
	[IBAVRT] [decimal](15, 0) NULL,
	[IBPOC] [nchar](1) NULL,
	[IBAING] [nchar](1) NULL,
	[IBBBDD] [decimal](6, 0) NULL,
	[IBCMDM] [nchar](1) NULL,
	[IBLECM] [nchar](1) NULL,
	[IBLEDD] [decimal](6, 0) NULL,
	[IBMLOT] [nchar](1) NULL,
	[IBPEFD] [decimal](6, 0) NULL,
	[IBSBDD] [decimal](6, 0) NULL,
	[IBU1DD] [decimal](6, 0) NULL,
	[IBU2DD] [decimal](6, 0) NULL,
	[IBU3DD] [decimal](6, 0) NULL,
	[IBU4DD] [decimal](6, 0) NULL,
	[IBU5DD] [decimal](6, 0) NULL,
	[IBXDCK] [nchar](1) NULL,
	[IBLAF] [nchar](1) NULL,
	[IBLTFM] [nchar](1) NULL,
	[IBRWLA] [nchar](1) NULL,
	[IBLNPA] [nchar](1) NULL,
	[IBLOTC] [nchar](3) NULL,
	[IBAPSC] [nchar](1) NULL,
	[IBPRI1] [decimal](15, 0) NULL,
	[IBPRI2] [decimal](15, 0) NULL,
	[IBLTCV] [decimal](15, 0) NULL,
	[IBASHL] [nchar](1) NULL,
	[IBOPTH] [decimal](5, 0) NULL,
	[IBCUTH] [decimal](5, 0) NULL,
	[IBUMTH] [nchar](3) NULL,
	[IBLMFG] [nchar](1) NULL,
	[IBLINE] [nchar](12) NULL,
	[IBDFTPCT] [decimal](20, 0) NULL,
	[IBKBIT] [nchar](1) NULL,
	[IBDFENDITM] [nchar](1) NULL,
	[IBKANEXLL] [nchar](1) NULL,
	[IBSCPSELL] [nchar](1) NULL,
PRIMARY KEY CLUSTERED 
(
	[IBMCU] ASC,
	[IBITM] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
ALTER AUTHORIZATION ON [dbo].[ItemBranchinDEV] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[JDEGSUDCUpdate]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[JDEGSUDCUpdate]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[JDEGSUDCUpdate](
	[SourceID] [int] NOT NULL,
	[Source] [nchar](20) NOT NULL,
	[InstallSystemCode] [nchar](4) NOT NULL,
	[UserDefinedCode] [nchar](2) NOT NULL,
	[UserDefinedCodesValues] [nchar](10) NOT NULL,
	[Description01] [nchar](30) NOT NULL,
	[InsertTimeStamp] [datetime] NOT NULL,
 CONSTRAINT [PK_JDEGSUDCUpdate] PRIMARY KEY CLUSTERED 
(
	[InstallSystemCode] ASC,
	[UserDefinedCode] ASC,
	[UserDefinedCodesValues] ASC,
	[InsertTimeStamp] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
ALTER AUTHORIZATION ON [dbo].[JDEGSUDCUpdate] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[JDEGSUDCUpdate_Error]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[JDEGSUDCUpdate_Error]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[JDEGSUDCUpdate_Error](
	[SourceID] [int] NOT NULL,
	[Source] [nchar](20) NOT NULL,
	[InstallSystemCode] [nchar](4) NOT NULL,
	[UserDefinedCode] [nchar](2) NOT NULL,
	[UserDefinedCodesValues] [nchar](10) NOT NULL,
	[Description01] [nchar](30) NOT NULL,
	[InsertTimeStamp] [datetime] NOT NULL
) ON [PRIMARY]
END
GO
ALTER AUTHORIZATION ON [dbo].[JDEGSUDCUpdate_Error] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[JDESOSalesOrderDetailHistory]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[JDESOSalesOrderDetailHistory]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[JDESOSalesOrderDetailHistory](
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[OrderNumberDocumentCompany] [char](5) NOT NULL,
	[OrderNumber] [int] NOT NULL,
	[OrderTypeCode] [char](2) NOT NULL,
	[LineNumber] [decimal](20, 7) NOT NULL,
	[OrderSuffix] [char](3) NOT NULL,
	[BusinessUnitCode] [char](12) NOT NULL,
	[CompanyNumber] [char](5) NOT NULL,
	[OriginalOrderDocumentCompany] [char](5) NOT NULL,
	[OriginalOrderNumber] [char](8) NOT NULL,
	[OriginalOrderTypeCode] [char](2) NOT NULL,
	[OriginalLineNumber] [decimal](20, 7) NOT NULL,
	[RelatedOrderKeyCompany] [char](5) NOT NULL,
	[RelatedPoSoWoNumber] [char](8) NOT NULL,
	[RelatedPoSoWoType] [char](2) NOT NULL,
	[RelatedPOSOLineNumber] [decimal](20, 7) NOT NULL,
	[ContractNumber] [char](12) NOT NULL,
	[ContractSupplement] [int] NOT NULL,
	[ContractBalancesUpdated] [char](1) NOT NULL,
	[AddressNumber] [int] NOT NULL,
	[ShipToNumber] [int] NOT NULL,
	[ParentNumber] [int] NOT NULL,
	[RequestedDate] [datetime] NOT NULL,
	[TransactionDate] [datetime] NOT NULL,
	[PromisedDeliveryDate] [datetime] NOT NULL,
	[OriginalPromisedDate] [datetime] NOT NULL,
	[ActualDeliveryDate] [datetime] NOT NULL,
	[InvoiceDate] [datetime] NOT NULL,
	[CancelDate] [datetime] NOT NULL,
	[GLDate] [datetime] NOT NULL,
	[PromisedDelivery] [datetime] NOT NULL,
	[PriceEffectiveDate] [datetime] NOT NULL,
	[ShipDate] [datetime] NOT NULL,
	[FutureUseDate] [datetime] NOT NULL,
	[Reference1] [char](25) NOT NULL,
	[Reference2] [char](25) NOT NULL,
	[ItemNumber] [int] NOT NULL,
	[ItemNumber02] [char](25) NOT NULL,
	[ItemNumber03] [char](25) NOT NULL,
	[Location] [char](20) NOT NULL,
	[LotNumber] [char](30) NOT NULL,
	[FromGrade] [char](3) NOT NULL,
	[ThruGrade] [char](3) NOT NULL,
	[FromPotency] [decimal](20, 7) NOT NULL,
	[ThruPotency] [decimal](20, 7) NOT NULL,
	[DaysBeforeExpiration] [int] NOT NULL,
	[Description01] [char](30) NOT NULL,
	[Description02] [char](30) NOT NULL,
	[LineType] [char](2) NOT NULL,
	[StatusCodeNext] [char](3) NOT NULL,
	[StatusCodeLast] [char](3) NOT NULL,
	[HeaderBusinessUnit] [char](12) NOT NULL,
	[RelatedItemNumber] [char](8) NOT NULL,
	[KitMasterLineNumber] [decimal](20, 7) NOT NULL,
	[ComponentLineNumber] [decimal](20, 7) NOT NULL,
	[RelatedKitComponent] [int] NOT NULL,
	[NumberOfComponentPerParent] [decimal](22, 7) NOT NULL,
	[SalesCategory01Code] [char](3) NOT NULL,
	[SalesCategory02Code] [char](3) NOT NULL,
	[SalesCategory03Code] [char](3) NOT NULL,
	[SalesCategory04Code] [char](3) NOT NULL,
	[SalesCategory05Code] [char](3) NOT NULL,
	[PurchasingCategory01Code] [char](3) NOT NULL,
	[PurchasingCategory02Code] [char](3) NOT NULL,
	[PurchasingCategory03Code] [char](3) NOT NULL,
	[PurchasingCategory04Code] [char](3) NOT NULL,
	[PurchasingCategory05Code] [char](3) NOT NULL,
	[UnitOfMeasureAsInput] [char](2) NOT NULL,
	[QuantityOrdered] [decimal](22, 7) NOT NULL,
	[QuantityShipped] [decimal](22, 7) NOT NULL,
	[QuantityBackordered] [decimal](22, 7) NOT NULL,
	[QuantityCanceled] [decimal](22, 7) NOT NULL,
	[FutureQuantityCommitted] [decimal](22, 7) NOT NULL,
	[QuantityOpen] [decimal](22, 7) NOT NULL,
	[QuantityShippedToDate] [decimal](22, 7) NOT NULL,
	[QuantityRelieved] [decimal](22, 7) NOT NULL,
	[CommittedHS] [char](1) NOT NULL,
	[OtherQuantity] [char](1) NOT NULL,
	[UnitPrice] [decimal](20, 7) NOT NULL,
	[ExtendedPrice] [decimal](20, 7) NOT NULL,
	[AmountOpen] [decimal](20, 7) NOT NULL,
	[PriceOverrideCode] [char](1) NOT NULL,
	[TemporaryPrice] [char](1) NOT NULL,
	[EnteredUOMForUnitPrice] [char](2) NOT NULL,
	[UnitListPrice] [decimal](20, 7) NOT NULL,
	[UnitCost] [decimal](20, 7) NOT NULL,
	[ExtendedCost] [decimal](20, 7) NOT NULL,
	[CostOverrideCode] [char](1) NOT NULL,
	[TransferCost] [decimal](20, 7) NOT NULL,
	[PrintMessage] [char](10) NOT NULL,
	[PaymentTerms] [char](3) NOT NULL,
	[PaymentInstrument] [char](1) NOT NULL,
	[BasedonDate] [char](1) NOT NULL,
	[TradeDiscount] [decimal](20, 7) NOT NULL,
	[TradeDiscountOld] [decimal](20, 7) NOT NULL,
	[AdjustmentSchedule] [char](8) NOT NULL,
	[ItemPriceGroupCode] [char](8) NOT NULL,
	[PricingCategoryLevel] [char](3) NOT NULL,
	[DiscountFactor] [decimal](20, 7) NOT NULL,
	[DiscFactorTypeDollarOrPercent] [char](1) NOT NULL,
	[DiscountApplicationType] [char](1) NOT NULL,
	[CashDiscountPercent] [decimal](20, 7) NOT NULL,
	[DocumentCompany] [char](5) NOT NULL,
	[DocumentNumber] [int] NOT NULL,
	[DocumentType] [char](2) NOT NULL,
	[OriginalDocumentNumber] [int] NOT NULL,
	[OriginalDocumentTypeCode] [char](2) NOT NULL,
	[OriginalDocumentCompany] [char](5) NOT NULL,
	[PickSlipNumber] [int] NOT NULL,
	[DeliveryNumber] [int] NOT NULL,
	[PromotionNumber] [char](8) NOT NULL,
	[DraftNumber] [int] NOT NULL,
	[SalesTaxable] [char](1) NOT NULL,
	[TaxRateArea] [char](10) NOT NULL,
	[TaxExplanationCode] [char](2) NOT NULL,
	[AssociatedText] [char](1) NOT NULL,
	[PriorityProcessingCode] [char](1) NOT NULL,
	[PrintedCode] [char](1) NOT NULL,
	[BackOrdersAllowed] [char](1) NOT NULL,
	[SubstitutesAllowed] [char](1) NOT NULL,
	[PartialShipmentsAllowed] [char](1) NOT NULL,
	[LineOfBusiness] [char](3) NOT NULL,
	[EndUse] [char](3) NOT NULL,
	[DutyStatus] [char](2) NOT NULL,
	[CommodityCode] [char](15) NOT NULL,
	[NatureofTransaction] [char](2) NOT NULL,
	[PrimaryLastSupplierNumber] [int] NOT NULL,
	[BuyerNumber] [int] NOT NULL,
	[PreferredCarrierSales] [int] NOT NULL,
	[ModeOfTransportation] [char](3) NOT NULL,
	[ConditionsOfTransportation] [char](3) NOT NULL,
	[RouteCode] [char](3) NOT NULL,
	[StopCode] [char](3) NOT NULL,
	[ZoneNumber] [char](3) NOT NULL,
	[ContainerID] [char](20) NOT NULL,
	[FreightHandlingCode] [char](3) NOT NULL,
	[ApplyFreightYN] [char](1) NOT NULL,
	[ApplyFreight] [char](1) NOT NULL,
	[FreightCalculated] [char](1) NOT NULL,
	[RateCodeFreightMisc] [char](10) NOT NULL,
	[RateTypeFreightMisc] [char](1) NOT NULL,
	[ShippingCommodityClass] [char](3) NOT NULL,
	[ShippingConditionsCode] [char](3) NOT NULL,
	[LotSerialNumber] [char](30) NOT NULL,
	[UnitOfMeasurePrimary] [char](2) NOT NULL,
	[PrimaryQuantityOrdered] [decimal](22, 7) NOT NULL,
	[UnitOfMeasureSecondary] [char](2) NOT NULL,
	[SecondaryQuantityOrdered] [decimal](22, 7) NOT NULL,
	[UnitOfMeasurePricing] [char](2) NOT NULL,
	[UnitWeight] [decimal](20, 7) NOT NULL,
	[WeightUOM] [char](2) NOT NULL,
	[UnitVolume] [decimal](20, 7) NOT NULL,
	[VolumeUOM] [char](2) NOT NULL,
	[BasketRepriceGroup] [char](8) NOT NULL,
	[OrderRepriceGroup] [char](8) NOT NULL,
	[OrderRepricedIndicator] [char](1) NOT NULL,
	[InventoryCostingMethod] [char](2) NOT NULL,
	[CommitmentMethod] [char](1) NOT NULL,
	[GLOffset] [char](4) NOT NULL,
	[Century] [int] NOT NULL,
	[FiscalYear] [int] NOT NULL,
	[LineStatus] [char](2) NOT NULL,
	[SalesOrderStatus01] [char](1) NOT NULL,
	[SalesOrderStatus02] [char](1) NOT NULL,
	[SalesOrderStatus03] [char](1) NOT NULL,
	[SalesOrderStatus04] [char](1) NOT NULL,
	[SalesOrderStatus05] [char](1) NOT NULL,
	[SalesOrderStatus06] [char](1) NOT NULL,
	[SalesOrderStatus07] [char](1) NOT NULL,
	[SalesOrderStatus08] [char](1) NOT NULL,
	[SalesOrderStatus09] [char](1) NOT NULL,
	[SalesOrderStatus10] [char](1) NOT NULL,
	[SalesOrderStatus11] [char](1) NOT NULL,
	[SalesOrderStatus12] [char](1) NOT NULL,
	[SalesOrderStatus13] [char](1) NOT NULL,
	[SalesOrderStatus14] [char](1) NOT NULL,
	[SalesOrderStatus15] [char](1) NOT NULL,
	[SalespersonCode01] [int] NOT NULL,
	[SalespersonCommission01] [decimal](20, 7) NOT NULL,
	[SalespersonCode02] [int] NOT NULL,
	[SalespersonCommission02] [decimal](20, 7) NOT NULL,
	[ApplyCommission] [char](1) NOT NULL,
	[CommissionCategory] [char](8) NOT NULL,
	[ReasonCode] [char](3) NOT NULL,
	[GrossWeight] [decimal](20, 7) NOT NULL,
	[GrossWeightUOM] [char](2) NOT NULL,
	[AccountNumber] [char](29) NOT NULL,
	[AccountID] [char](8) NOT NULL,
	[PurchasingBusinessUnit] [char](12) NOT NULL,
	[ObjectAccount] [char](6) NOT NULL,
	[Subsidiary] [char](8) NOT NULL,
	[LedgerTypeCode] [char](2) NOT NULL,
	[SubLedger] [char](8) NOT NULL,
	[SubledgerType] [char](1) NOT NULL,
	[LocalTaxCode] [char](2) NOT NULL,
	[PriceCode1] [char](2) NOT NULL,
	[PriceCode2] [char](2) NOT NULL,
	[PriceCode3] [char](2) NOT NULL,
	[WarehouseStatusCode] [char](1) NOT NULL,
	[FreezeCode] [char](1) NOT NULL,
	[SendMethod] [char](1) NOT NULL,
	[CurrencyCode] [char](3) NOT NULL,
	[CurrencyConversionRateSpot] [decimal](20, 7) NOT NULL,
	[ForeignListPrice] [decimal](20, 7) NOT NULL,
	[ForeignUnitPrice] [decimal](20, 7) NOT NULL,
	[ForeignExtendedPrice] [decimal](20, 7) NOT NULL,
	[ForeignUnitCost2] [decimal](20, 7) NOT NULL,
	[ForeignExtendedCost] [decimal](20, 7) NOT NULL,
	[UserReservedCode] [char](2) NOT NULL,
	[UserReservedDate] [datetime] NOT NULL,
	[UserReservedAmount] [decimal](20, 7) NOT NULL,
	[UserReservedNumber] [int] NOT NULL,
	[UserReservedReference] [char](15) NOT NULL,
	[TransactionOriginator] [char](10) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[TimeOfDay] [int] NOT NULL,
	[ManufacturingVarianceAcctFlag] [char](1) NOT NULL,
	[SalesOrderStatus17] [char](1) NOT NULL,
	[SalesOrderStatus18] [char](1) NOT NULL,
	[SalesOrderStatus19] [char](1) NOT NULL,
	[SalesOrderStatus20] [char](1) NOT NULL,
	[IntegrationReference01] [char](30) NOT NULL,
	[IntegrationReference02] [char](30) NOT NULL,
	[IntegrationReference03] [char](30) NOT NULL,
	[IntegrationReference04] [char](30) NOT NULL,
	[IntegrationReference05] [char](30) NOT NULL,
	[SourceofOrder] [int] NOT NULL,
	[Reference] [char](25) NOT NULL,
	[DemandUniqueKeyID] [int] NOT NULL,
	[PullSignal] [char](30) NOT NULL,
	[ReleaseNumber] [char](10) NOT NULL,
	[ScheduledShipmentTime] [int] NOT NULL,
	[TimeRelease] [int] NOT NULL,
	[DateRelease] [datetime] NOT NULL,
	[RequestedDeliveryTime] [int] NOT NULL,
	[ActualShipmentTime] [int] NOT NULL,
	[TimeOriginalPromisedDelivery] [int] NOT NULL,
	[TimeScheduledPick] [int] NOT NULL,
	[TimeFutureTime2] [int] NOT NULL,
	[CrossDockingFlag] [char](1) NOT NULL,
	[CrossDockingPriorityforSalesO] [decimal](28, 0) NOT NULL,
	[DualUnitOfMeasureItem] [char](1) NOT NULL,
	[BuyingSegmentCode] [char](10) NOT NULL,
	[CurrentBuyingSegmentCode] [char](10) NOT NULL,
	[ChangeOrderNumber] [int] NOT NULL,
	[AddressNumberDeliverTo] [int] NOT NULL,
	[PendingApprovalFlag] [char](1) NOT NULL,
	[RevisionReason] [char](6) NOT NULL,
	[MatrixControlLineNumber] [decimal](20, 7) NOT NULL,
	[ShipmentNumber] [int] NOT NULL,
	[PromisedDeliveryTime] [int] NOT NULL,
	[ProjectNumber] [int] NOT NULL,
	[SequenceNumber] [int] NOT NULL,
	[ItemRevisionLevel] [char](3) NOT NULL,
	[HoldOrdersCode] [char](2) NOT NULL,
	[BusinessUnitHeader] [char](12) NOT NULL,
	[BusinessUnitDemand] [char](12) NOT NULL,
	[CurrencyCodeBase] [char](3) NOT NULL,
	[DocumentLineNumberOriginal] [decimal](20, 7) NOT NULL,
	[CrossDockOrderCompanyOrderNum] [char](10) NOT NULL,
	[CrossDockOrderNo] [int] NOT NULL,
	[CrossDockOrderType] [char](4) NOT NULL,
	[CrossDockLineNumber] [decimal](20, 7) NOT NULL,
	[CrossDockOrderSuffix] [char](3) NOT NULL,
	[PortofEntryorExit] [char](6) NOT NULL,
	[PaymentTermsOverrideCode] [char](1) NOT NULL,
	[PromotionID] [char](12) NOT NULL,
	[AssetItemNumber] [int] NOT NULL,
	[ParentNumberAAID] [int] NOT NULL,
	[ShipToAttention] [char](50) NOT NULL,
	[PartnerAddressNumber] [int] NOT NULL,
	[PartnerContactLineNumberID] [int] NOT NULL,
	[CustomerContactLineNumberID] [int] NOT NULL,
	[ShipToCustContactLineNumID] [int] NOT NULL,
	[OpportunityNumber] [int] NOT NULL,
	[OrganizationStructureType] [char](3) NOT NULL,
	[UniqueKeyIDInternal] [int] NOT NULL,
	[CatalogName] [char](30) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_JDESOSalesOrderDetailHistory] PRIMARY KEY CLUSTERED 
(
	[OrderNumber] ASC,
	[OrderNumberDocumentCompany] ASC,
	[LineNumber] ASC,
	[OrderTypeCode] ASC,
	[OrderSuffix] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
ALTER AUTHORIZATION ON [dbo].[JDESOSalesOrderDetailHistory] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[MobileUserProfiles]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MobileUserProfiles]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[MobileUserProfiles](
	[FFUSER] [nchar](10) NOT NULL,
	[FFROUT] [nchar](3) NOT NULL,
	[FFMCU] [nchar](12) NOT NULL,
	[FFHMCU] [nchar](12) NULL,
	[FFBUVAL] [nchar](12) NULL,
	[FFAN8] [numeric](8, 0) NULL,
	[FFPA8] [numeric](8, 0) NULL,
	[FFSTOP] [nchar](3) NULL,
	[FFZON] [nchar](3) NULL,
	[FFLOCN] [nchar](20) NULL,
	[FFLOCF] [nchar](20) NULL,
	[FFEV01] [nchar](1) NULL,
	[FFEV02] [nchar](1) NULL,
	[FFEV03] [nchar](1) NULL,
	[FFMATH01] [decimal](15, 0) NULL,
	[FFMATH02] [decimal](15, 0) NULL,
	[FFMATH03] [decimal](15, 0) NULL,
	[FFCXPJ] [numeric](6, 0) NULL,
	[FFCLRJ] [numeric](6, 0) NULL,
	[FFDTE] [numeric](6, 0) NULL,
	[FFUPMB] [nchar](10) NULL,
	[FFPID] [nchar](10) NULL,
	[FFJOBN] [nchar](10) NULL,
	[FFUPMJ] [numeric](6, 0) NULL,
	[FFUPMT] [numeric](6, 0) NULL,
PRIMARY KEY CLUSTERED 
(
	[FFUSER] ASC,
	[FFROUT] ASC,
	[FFMCU] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
ALTER AUTHORIZATION ON [dbo].[MobileUserProfiles] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[UEtbl_UDC_bef]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UEtbl_UDC_bef]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[UEtbl_UDC_bef](
	[DRSY] [char](4) NULL,
	[DRRT] [char](2) NULL,
	[DRKY] [char](10) NULL,
	[DRDL01] [char](30) NULL,
	[DRDL02] [char](30) NULL,
	[DRSPHD] [char](10) NULL,
	[DRUDCO] [char](1) NULL,
	[DRHRDC] [char](1) NULL,
	[DRUSER] [char](10) NULL,
	[DRPID] [char](10) NULL,
	[DRUPMJ] [decimal](18, 0) NULL,
	[DRJOBN] [char](10) NULL,
	[DRUPMT] [float] NULL,
	[DEFAULTDATE] [char](26) NULL
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
ALTER AUTHORIZATION ON [dbo].[UEtbl_UDC_bef] TO  SCHEMA OWNER 
GO
/****** Object:  Table [dbo].[UEtbl_UDC_upd]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UEtbl_UDC_upd]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[UEtbl_UDC_upd](
	[SourceID] [int] NOT NULL,
	[Source] [char](20) NOT NULL,
	[InstallSystemCode] [char](4) NOT NULL,
	[UserDefinedCode] [char](2) NOT NULL,
	[UserDefinedCodesValues] [char](10) NOT NULL,
	[Description01] [char](30) NOT NULL,
	[Description02] [char](30) NOT NULL,
	[SpecialHandlingCode] [char](10) NOT NULL,
	[OwnershipFlag] [char](1) NOT NULL,
	[HardCodedYN] [char](1) NOT NULL,
	[UserID] [char](10) NOT NULL,
	[ProgramID] [char](10) NOT NULL,
	[DateUpdated] [datetime] NOT NULL,
	[WorkStationID] [char](10) NOT NULL,
	[LastTimeUpdated] [decimal](6, 0) NOT NULL,
	[InsertIndicator] [int] NOT NULL,
	[InsertDate] [datetime] NOT NULL,
	[ChangeIndicator] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[DeleteIndicator] [int] NOT NULL,
	[DeleteDate] [datetime] NOT NULL,
	[PurgeDate] [datetime] NOT NULL
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
ALTER AUTHORIZATION ON [dbo].[UEtbl_UDC_upd] TO  SCHEMA OWNER 
GO
/****** Object:  View [dbo].[FBSalesOrgStructure]    Script Date: 5/30/13 10:27:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[FBSalesOrgStructure]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[FBSalesOrgStructure]
AS
SELECT     dbo.FBSalesOrganizationStructure.*
FROM         dbo.FBSalesOrganizationStructure
' 
GO
ALTER AUTHORIZATION ON [dbo].[FBSalesOrgStructure] TO  SCHEMA OWNER 
GO
IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_DiagramPane1' , N'SCHEMA',N'dbo', N'VIEW',N'FBSalesOrgStructure', NULL,NULL))
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "FBSalesOrganizationStructure"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 121
               Right = 227
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'FBSalesOrgStructure'
GO
IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_DiagramPaneCount' , N'SCHEMA',N'dbo', N'VIEW',N'FBSalesOrgStructure', NULL,NULL))
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'FBSalesOrgStructure'
GO
USE [master]
GO
ALTER DATABASE [RD4_DWCRWork] SET  READ_WRITE 
GO
